"""
RBAC上下文处理器
为所有模板提供权限检查功能
"""

def rbac_context(request):
    """
    为模板提供RBAC相关的上下文变量
    """
    context = {}
    
    # 提供权限检查函数
    if hasattr(request, 'has_permission'):
        context['has_permission'] = request.has_permission
    else:
        context['has_permission'] = lambda perm_code: False
    
    # 提供当前用户信息
    if hasattr(request, 'current_user'):
        context['current_user'] = request.current_user
        # 检查是否为超级用户或管理员
        context['is_admin'] = (
            request.current_user.get('is_superuser', False) or 
            'admin' in request.current_user.get('roles', []) or
            'super_admin' in request.current_user.get('roles', [])
        )
    else:
        context['current_user'] = {}
        context['is_admin'] = False
    
    return context